//
//  ZXZMyCustomAddViewController.m
//  sheyingzu
//
//  Created by tyu on 29.5.24.
//

#import "ZXZMyCustomAddViewController.h"

@interface ZXZMyCustomAddViewController ()<UITextViewDelegate,UIScrollViewDelegate>


@property(nonatomic,weak) UIScrollView *ScrollView;

@property(nonatomic,weak) UIView *topView;
@property(nonatomic,weak) UITextView *TitleTextView;
@property(nonatomic, weak)UILabel *placeHolder;


@property(nonatomic,weak) UIView *middView;
@property(nonatomic,weak) UITextField *dayTextF;

@property(nonatomic,weak) UIView *bottomView;
@property(nonatomic,weak) UITextField *phoneTextF;



@end

@implementation ZXZMyCustomAddViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIView ColorWithHexString:@"#F8F9FB" alpha:1];


}



- (void)bac_addUI
{
    [super bac_addUI];
    [self setupView];
    self.bacTitleLabel.text = @"添加定制";
    [self.view bringSubviewToFront:self.navView];
    
    
    
}
- (void)addBtnClick
{

    if (self.TitleTextView.text.length<=0) {
        [NotifyLabel NotifyWithString:@"请输入您的定制内容"];
        return;
    }else if (self.dayTextF.text.length <=0){
        [NotifyLabel NotifyWithString:@"请输入您的租赁时间"];
        return;

    }else if (self.phoneTextF.text.length <=0){
        [NotifyLabel NotifyWithString:@"请输入您的联系方式"];
        return;

    }else if ([self.dayTextF.text floatValue]<90){
        [NotifyLabel NotifyWithString:@"租赁时间不能小于90天"];
        return;
    }
    
    [userDef setValue:@"1" forKey:@"dingzhi"];
    [userDef setValue:self.TitleTextView.text forKey:@"dingzhititle"];
    [userDef setValue:self.dayTextF.text forKey:@"dingzhiday"];
    [userDef setValue:self.phoneTextF.text forKey:@"dingzhiphone"];

    [NotifyLabel NotifyWithString:@"定制成功"];

    
}



- (void)setupView{
    
    UIScrollView *ScrollV = [[UIScrollView alloc]init];
    [self.view addSubview:ScrollV];
    self.ScrollView =ScrollV;
    ScrollV.delegate = self;

    ScrollV.contentSize = CGSizeMake(ScreenWidth, ScreenHeight*1.1);
    ScrollV.contentInset = UIEdgeInsetsMake(0, 0, -10, 0);
    ScrollV.showsVerticalScrollIndicator = NO;
    ScrollV.frame = CGRectMake(0, 100, ScreenWidth, ScreenHeight-ShowDiff);
    
    [self setTopView];
    [self setupMiddView];
    [self setupBottomView];

    
    UILabel *bottLab = [self lableWithText:@"留下联系方式方便客服更快审核你的定制需求" andColor:[UIView ColorWithHexString:@"#999999"] andFont:12];
    [ScrollV addSubview:bottLab];
    bottLab.frame = CGRectMake(20, CGRectGetMaxY(self.bottomView.frame)+10, 200, 20);
    
    
    
    UIButton *addBtn = [[UIButton alloc] init];
    [ScrollV addSubview:addBtn];
    addBtn.frame = CGRectMake(20, CGRectGetMaxY(bottLab.frame)+60, ScreenWidth-40, 44);
    [addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [addBtn setTitle:@"立即定制" forState:UIControlStateNormal];
    addBtn.backgroundColor = [UIView ColorWithHexString:@"#07C6D2"];
    addBtn.layer.cornerRadius = 44/2;
    addBtn.layer.masksToBounds = YES;
}


- (void)setTopView
{
    
    UIView *view = [UIView new];
    [self.ScrollView addSubview:view];
    self.topView =view;
    view.frame = CGRectMake(15, 50, ScreenWidth-30, 150);
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 10;
    view.layer.masksToBounds = YES;
    

    UITextView *TitleTextView = [[UITextView alloc]init];
    self.TitleTextView = TitleTextView;
    [view addSubview:TitleTextView];
    self.TitleTextView.delegate = self;
    self.TitleTextView.font = [UIFont systemFontOfSize:16];
    TitleTextView.frame = CGRectMake(5, 5, ScreenWidth-30-19, 100);

    [self setupPlaceHolder];

}




// 给textView添加一个UILabel子控件
- (void)setupPlaceHolder
{
    UILabel *placeHolder = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, ScreenWidth - 2 * 15, 20)];
    self.placeHolder = placeHolder;
 
    placeHolder.text = @"请输入你想定制的机型品牌及型号等";
    placeHolder.textColor = [UIColor lightGrayColor];
    placeHolder.numberOfLines = 0;
    placeHolder.contentMode = UIViewContentModeTop;
    [self.TitleTextView addSubview:placeHolder];
}
 
#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
    if (!textView.text.length) {
    self.placeHolder.alpha = 1;
    } else {
        self.placeHolder.alpha = 0;
    }
}



- (void)setupMiddView
{
    
    UIView *view = [UIView new];
    [self.ScrollView addSubview:view];
    self.middView =view;
    view.frame = CGRectMake(15, CGRectGetMaxY(self.topView.frame)+10, ScreenWidth-30, 100);
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 10;
    view.layer.masksToBounds = YES;
    
    
    UILabel *leftTitle  = [[UILabel alloc]init];
    [view addSubview:leftTitle];
    leftTitle.font = [UIFont systemFontOfSize:16];
    leftTitle.textColor = [UIColor blackColor];
    leftTitle.text = @"租赁时长";
    leftTitle.frame = CGRectMake(10, 10, 80, 20);
    
    UILabel *rightTitle  = [[UILabel alloc]init];
    [view addSubview:rightTitle];
    rightTitle.font = [UIFont systemFontOfSize:16];
    rightTitle.textColor = [UIView ColorWithHexString:@"#999999"];
    rightTitle.text = @"定制机租赁时长不能少于90天";
    rightTitle.frame = CGRectMake(CGRectGetMaxX(leftTitle.frame)+10, 10, 250, 20);

    
    UITextField *TextF=[[UITextField alloc]init];
    [view addSubview:TextF];
    self.dayTextF = TextF;
    TextF.borderStyle=UITextBorderStyleNone;
    TextF.placeholder = @"请输入租赁时长";
    TextF.keyboardType = UIKeyboardTypePhonePad;
    TextF.frame = CGRectMake(10, CGRectGetMaxY(leftTitle.frame)+20, 150, 30);

    
    UILabel *dayLab = [self lableWithText:@"天" andColor:[UIColor blackColor] andFont:16];
    [view addSubview:dayLab];
    dayLab.frame = CGRectMake(CGRectGetMaxX(TextF.frame)+10, CGRectGetMinY(TextF.frame), 30, 30);


}


- (void)setupBottomView
{
    
    UIView *view = [UIView new];
    [self.ScrollView addSubview:view];
    self.bottomView =view;
    view.frame = CGRectMake(15, CGRectGetMaxY(self.middView.frame)+10, ScreenWidth-30, 100);
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 10;
    view.layer.masksToBounds = YES;
    
    
    UILabel *leftTitle = [self lableWithText:@"请留下联系方式" andColor:[UIColor blackColor] andFont:16];
    [view addSubview:leftTitle];
    leftTitle.frame = CGRectMake(10, 10, 150, 20);
    
    UITextField *TextF=[[UITextField alloc]init];
    [view addSubview:TextF];
    self.phoneTextF = TextF;
    TextF.borderStyle=UITextBorderStyleNone;
    TextF.placeholder = @"请输入联系方式";
    TextF.keyboardType = UIKeyboardTypePhonePad;
    TextF.frame = CGRectMake(10, CGRectGetMaxY(leftTitle.frame)+20, 200, 30);



}

- (UILabel *)lableWithText:(NSString *)title andColor:(UIColor *)color andFont:(CGFloat )font
{
    
    UILabel *rightTitle  = [[UILabel alloc]init];
    rightTitle.font = [UIFont systemFontOfSize:font];
    rightTitle.textColor = color;
    rightTitle.text = title;
    return rightTitle;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
    
}


@end
